package com.hissy.common.activemq;

import javax.jms.Connection;
import javax.jms.JMSException;

import org.apache.activemq.ActiveMQConnectionFactory;

/**
 * Created by zhangyanfei on 2017/12/5.
 *
 * @author zhangyanfei
 * @date 2017/12/05
 *
 * ActiveMq 客户端工厂类
 */
public class ActiveMqClientFactory {
    private static ActiveMQConnectionFactory activeMQConnectionFactory;
    private static ActiveMqClientFactory activeMqClientFactory;

    private ActiveMqClientFactory() {
        activeMQConnectionFactory = new ActiveMQConnectionFactory(ActiveMqConfig.getUserName(),
            ActiveMqConfig.getPassword(), ActiveMqConfig.getBrokerUrl());
    }

    public static ActiveMqClientFactory getInstance() {
        if (activeMqClientFactory == null) {
            activeMqClientFactory = new ActiveMqClientFactory();
        }
        return activeMqClientFactory;
    }

    public  Connection getActiveMqConnection() throws JMSException {
        return activeMQConnectionFactory.createConnection();
    }
}
